home *** CD-ROM | disk | FTP | other *** search
/ Dr. Windows 3 / dr win3.zip / dr win3 / PROGRAMR / OLE2BOOK.ZIP / CHAP09.ZIP / CHAP09 / PATRON / PATRON.CPP < prev    next >
C/C++ Source or Header  |  1993-06-15  |  13KB  |  543 lines

  1. /*
  2.  * PATRON.CPP
  3.  * Modifications for Chapter 9
  4.  *
  5.  * WinMain which is all we need for the basic application.
  6.  *
  7.  * Copyright (c)1993 Microsoft Corporation, All Rights Reserved
  8.  *
  9.  * Kraig Brockschmidt, Software Design Engineer
  10.  * Microsoft Systems Developer Relations
  11.  *
  12.  * Internet  :  kraigb@microsoft.com
  13.  * Compuserve:  >INTERNET:kraigb@microsoft.com
  14.  */
  15.  
  16.  
  17. #define INITGUIDS
  18. #include "patron.h"
  19.  
  20.  
  21.  
  22. /*
  23.  * WinMain
  24.  *
  25.  * Purpose:
  26.  *  Main entry point of application.   Should register the app class
  27.  *  if a previous instance has not done so and do any other one-time
  28.  *  initializations.
  29.  */
  30.  
  31. int PASCAL WinMain (HINSTANCE hInst, HINSTANCE hPrev
  32.     , LPSTR pszCmdLine, int nCmdShow)
  33.     {
  34.     LPCPatronFrame  pFR;
  35.     FRAMEINIT       fi;
  36.     WPARAM          wRet;
  37.  
  38.    #ifndef WIN32
  39.     SetMessageQueue(96);
  40.    #endif
  41.  
  42.     //Attempt to allocate and initialize the application
  43.     pFR=new CPatronFrame(hInst, hPrev, pszCmdLine, nCmdShow);
  44.  
  45.     fi.idsMin=IDS_FRAMEMIN;
  46.     fi.idsMax=IDS_FRAMEMAX;
  47.     fi.idsStatMin=IDS_STATMESSAGEMIN;
  48.     fi.idsStatMax=IDS_STATMESSAGEMAX;
  49.     fi.idStatMenuMin=ID_MENUFILE;
  50.     fi.idStatMenuMax=ID_MENUHELP;
  51.     fi.iPosWindowMenu=WINDOW_MENU;
  52.     fi.cMenus=CMENUS;
  53.  
  54.     //If we can initialize pFR, start chugging messages
  55.     if (pFR->FInit(&fi))
  56.         wRet=pFR->MessageLoop();
  57.  
  58.     delete pFR;
  59.     return wRet;
  60.     }
  61.  
  62.  
  63.  
  64.  
  65. /*
  66.  * CPatronFrame::CPatronFrame
  67.  * CPatronFrame::~CPatronFrame
  68.  *
  69.  * Constructor Parameters:
  70.  *  hInst           HINSTANCE from WinMain
  71.  *  hInstPrev       HINSTANCE from WinMain
  72.  *  pszCmdLine      LPSTR from WinMain
  73.  *  nCmdShow        int from WInMain
  74.  */
  75.  
  76. CPatronFrame::CPatronFrame(HINSTANCE hInst, HINSTANCE hInstPrev
  77.     , LPSTR pszCmdLine, int nCmdShow)
  78.     : CFrame(hInst, hInstPrev, pszCmdLine, nCmdShow)
  79.     {
  80.     m_fInitialized=FALSE;
  81.     return;
  82.     }
  83.  
  84.  
  85. CPatronFrame::~CPatronFrame(void)
  86.     {
  87.     OleFlushClipboard();
  88.  
  89.     if (m_fInitialized)
  90.         OleUninitialize();
  91.     return;
  92.     }
  93.  
  94.  
  95.  
  96.  
  97. /*
  98.  * CPatronFrame::FInit
  99.  *
  100.  * Purpose:
  101.  *  Call OleInitialize then calling down into the base class
  102.  *  initialization.
  103.  *
  104.  * Parameters:
  105.  *  pFI             LPFRAMEINIT containing initialization parameters.
  106.  *
  107.  * Return Value:
  108.  *  BOOL            TRUE if initialization succeeded, FALSE otherwise.
  109.  */
  110.  
  111. BOOL CPatronFrame::FInit(LPFRAMEINIT pFI)
  112.     {
  113.     DWORD       dwVer;
  114.  
  115.     dwVer=OleBuildVersion();
  116.  
  117.     if (rmm!=HIWORD(dwVer))
  118.         return FALSE;
  119.  
  120.     if (FAILED(OleInitialize(NULL)))
  121.         return FALSE;
  122.  
  123.     m_fInitialized=TRUE;
  124.  
  125.     return CFrame::FInit(pFI);
  126.     }
  127.  
  128.  
  129.  
  130.  
  131.  
  132. /*
  133.  * CPatronFrame::CreateCClient
  134.  *
  135.  * Purpose:
  136.  *  Constructs a new client specific to the application.
  137.  *
  138.  * Parameters:
  139.  *  None
  140.  *
  141.  * Return Value:
  142.  *  LPCClient       Pointer to the new client object.
  143.  */
  144.  
  145. LPCClient CPatronFrame::CreateCClient(void)
  146.     {
  147.     return (LPCClient)(new CPatronClient(m_hInst));
  148.     }
  149.  
  150.  
  151.  
  152.  
  153.  
  154.  
  155. /*
  156.  * CPatronFrame::FRegisterAllClasses
  157.  *
  158.  * Purpose:
  159.  *  Registers all classes used in this application.
  160.  *
  161.  * Parameters:
  162.  *  None
  163.  *
  164.  * Return Value:
  165.  *  BOOL            TRUE if registration succeeded, FALSE otherwise.
  166.  */
  167.  
  168. BOOL CPatronFrame::FRegisterAllClasses(void)
  169.     {
  170.     WNDCLASS        wc;
  171.  
  172.     //First let the standard frame do its thing
  173.     if (!CFrame::FRegisterAllClasses())
  174.         return FALSE;
  175.  
  176.     //We need double-clicks now and for object activation later.
  177.     wc.style         = CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS;
  178.     wc.hInstance     = m_hInst;
  179.     wc.cbClsExtra    = 0;
  180.     wc.lpfnWndProc   = PagesWndProc;
  181.     wc.cbWndExtra    = CBPAGESWNDEXTRA;
  182.     wc.hIcon         = NULL;
  183.     wc.hCursor       = LoadCursor(NULL, IDC_ARROW);
  184.     wc.hbrBackground = (HBRUSH)(COLOR_APPWORKSPACE+1);
  185.     wc.lpszMenuName  = NULL;
  186.     wc.lpszClassName = SZCLASSPAGES;
  187.  
  188.     if (!RegisterClass(&wc))
  189.         return FALSE;
  190.  
  191.     return TRUE;
  192.     }
  193.  
  194.  
  195.  
  196.  
  197.  
  198. /*
  199.  * CPatronFrame::OnCommand
  200.  *
  201.  * Purpose:
  202.  *  WM_COMMAND handler for the Patron frame window that processes extra
  203.  *  File menu items as well as the Page menu.
  204.  *
  205.  * Parameters:
  206.  *  hWnd            HWND of the frame window.
  207.  *  wParam          WPARAM of the message.
  208.  *  lParam          LPARAM of the message.
  209.  *
  210.  * Return Value:
  211.  *  LRESULT         Return value for the message.
  212.  */
  213.  
  214. LRESULT CPatronFrame::OnCommand(HWND hWnd, WPARAM wParam, LPARAM lParam)
  215.     {
  216.     LPCPatronDoc    pDoc;
  217.  
  218.     COMMANDPARAMS(wID, wCode, hWndMsg);
  219.  
  220.     /*
  221.      * Don't bother with anything during first initialization,
  222.      * skipping many GizmoBar notifications.
  223.      */
  224.     if (m_fInit)
  225.         return 0L;
  226.  
  227.     pDoc=(LPCPatronDoc)m_pCL->ActiveDocument();
  228.  
  229.     //CHAPTER9MOD
  230.     if (NULL!=pDoc && (IDM_VERBMIN <= wID) && (IDM_VERBMAX >= wID))
  231.         {
  232.         pDoc->ActivateObject(wID-IDM_VERBMIN);
  233.         return 0L;
  234.         }
  235.     //End CHAPTER9MOD
  236.  
  237.     switch (wID)
  238.         {
  239.         case IDM_FILEPRINT:
  240.             pDoc->Print(m_hWnd);
  241.             return 0L;
  242.  
  243.         case IDM_FILEPRINTERSETUP:
  244.             pDoc->PrinterSetup(m_hWnd, FALSE);
  245.             return 0L;
  246.  
  247.  
  248.         case IDM_EDITPASTESPECIAL:
  249.             pDoc->FPasteSpecial(m_hWnd);
  250.             return 0L;
  251.  
  252.         case IDM_EDITDELETEOBJECT:
  253.             pDoc->Delete();
  254.             return 0L;
  255.  
  256.         //CHAPTER9MOD
  257.         case IDM_EDITINSERTOBJECT:
  258.             pDoc->FInsertObject(m_hWnd);
  259.             return 0L;
  260.         //End CHAPTER9MOD
  261.  
  262.  
  263.         case IDM_PAGENEWPAGE:
  264.             pDoc->NewPage();
  265.             break;
  266.  
  267.         case IDM_PAGEDELETEPAGE:
  268.             pDoc->DeletePage();
  269.             break;
  270.  
  271.         case IDM_PAGENEXTPAGE:
  272.             pDoc->NextPage();
  273.             break;
  274.  
  275.         case IDM_PAGEPREVIOUSPAGE:
  276.             pDoc->PreviousPage();
  277.             break;
  278.  
  279.         case IDM_PAGEFIRSTPAGE:
  280.             pDoc->FirstPage();
  281.             break;
  282.  
  283.         case IDM_PAGELASTPAGE:
  284.             pDoc->LastPage();
  285.             break;
  286.  
  287.  
  288.         default:
  289.            return CFrame::OnCommand(hWnd, wParam, lParam);
  290.         }
  291.  
  292.     return 0L;
  293.     }
  294.  
  295.  
  296.  
  297.  
  298.  
  299.  
  300.  
  301.  
  302. /*
  303.  * CPatronFrame::CreateGizmos
  304.  *
  305.  * Purpose:
  306.  *  Procedure to create all the necessary gizmobar buttons.
  307.  *
  308.  * Parameters:
  309.  *  None
  310.  *
  311.  * Return Value:
  312.  *  UINT            Number of gizmos added to the bar.
  313.  */
  314.  
  315. UINT CPatronFrame::CreateGizmos(void)
  316.     {
  317.     UINT            iLast;
  318.     UINT            uState=GIZMO_NORMAL;
  319.     UINT            utCmd =GIZMOTYPE_BUTTONCOMMAND;
  320.  
  321.     //Insert the standard ones.
  322.     iLast=CFrame::CreateGizmos();
  323.  
  324.     //Insert Print File Import in the 5th position and account for it in iLast.
  325.     m_pGB->Add(utCmd, 4, IDM_FILEPRINT, m_dxB, m_dyB, NULL, NULL, 6, uState);
  326.     iLast++;
  327.  
  328.     //Add New Page, and Delete Page
  329.     m_pGB->Add(utCmd, iLast++, IDM_PAGENEWPAGE,    m_dxB, m_dyB, NULL, m_hBmp, 2, uState);
  330.     m_pGB->Add(utCmd, iLast++, IDM_PAGEDELETEPAGE, m_dxB, m_dyB, NULL, m_hBmp, 3, uState);
  331.  
  332.     //Separator
  333.     m_pGB->Add(GIZMOTYPE_SEPARATOR, iLast++, 0, 6, m_dyB, NULL, NULL, 0, uState);
  334.  
  335.     //First, Prev, Next, Last pages.
  336.     m_pGB->Add(utCmd, iLast++, IDM_PAGEFIRSTPAGE,    m_dxB, m_dyB, NULL, m_hBmp, 4, uState);
  337.     m_pGB->Add(utCmd, iLast++, IDM_PAGEPREVIOUSPAGE, m_dxB, m_dyB, NULL, m_hBmp, 5, uState);
  338.     m_pGB->Add(utCmd, iLast++, IDM_PAGENEXTPAGE,     m_dxB, m_dyB, NULL, m_hBmp, 6, uState);
  339.     m_pGB->Add(utCmd, iLast++, IDM_PAGELASTPAGE,     m_dxB, m_dyB, NULL, m_hBmp, 7, uState);
  340.  
  341.     return iLast;
  342.     }
  343.  
  344.  
  345.  
  346.  
  347.  
  348.  
  349.  
  350. /*
  351.  * CPatronFrame::UpdateMenus
  352.  *
  353.  * Purpose:
  354.  *  Handles the WM_INITMENU message for the frame window.  Depending
  355.  *  on the existence of an active window, menu items are selectively
  356.  *  enabled and disabled.
  357.  *
  358.  * Parameters:
  359.  *  hMenu           HMENU of the menu to intialize
  360.  *  iMenu           UINT position of the menu.
  361.  *
  362.  * Return Value:
  363.  *  None
  364.  */
  365.  
  366. void CPatronFrame::UpdateMenus(HMENU hMenu, UINT iMenu)
  367.     {
  368.     LPCPatronDoc    pDoc;
  369.     BOOL            fOK=FALSE;
  370.     BOOL